﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class HoiDap : System.Web.UI.Page
{
    DangNhap dn = new DangNhap();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            if (Session["user"] != null)
            {
                MultiView1.SetActiveView(View3);
                GridView3.DataSource = dn.DSHoiDap();
                GridView3.DataBind();
            }
            else
                Response.Redirect("DangNhap.aspx");
        }
  
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        GridView3.DataSource = dn.TimCauHoi(TextBox17.Text,TextBox18.Text);
        GridView3.DataBind();
    }
    protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string nguoihoi = GridView3.Rows[e.RowIndex].Cells[1].Text;

        TextBox txtEmail = (TextBox)GridView3.Rows[e.RowIndex].Cells[2].Controls[0];
        string Email = txtEmail.Text;

        TextBox txtChude = (TextBox)GridView3.Rows[e.RowIndex].Cells[3].Controls[0];
        string chude = txtChude.Text;

        TextBox txthoi = (TextBox)GridView3.Rows[e.RowIndex].Cells[4].Controls[0];
        string hoi = txthoi.Text;

        TextBox txtdap = (TextBox)GridView3.Rows[e.RowIndex].Cells[5].Controls[0];
        string dap = txtdap.Text;

        TextBox txtngayhoi = (TextBox)GridView3.Rows[e.RowIndex].Cells[6].Controls[0];
        string ngayhoi = txtngayhoi.Text;

        TextBox txtNgaydap = (TextBox)GridView3.Rows[e.RowIndex].Cells[7].Controls[0];
        string ngyadap = txtNgaydap.Text;

        TextBox txtnguoidap = (TextBox)GridView3.Rows[e.RowIndex].Cells[8].Controls[0];
        string nguoidap = txtnguoidap.Text;

        RadioButtonList rd = (RadioButtonList)GridView3.Rows[e.RowIndex].Cells[9].FindControl("RadioButtonList1");
        bool ht = true;
        if (rd.Items[0].Selected == true)
            ht = true;
        else
            ht = false;

        dn.SuaHoiDap(nguoihoi, Email, chude, hoi, dap, ngayhoi, ngyadap, nguoidap, ht);

        GridView3.EditIndex = -1;
        GridView3.DataSource = dn.DSHoiDap();
        GridView3.DataBind();
    }
    protected void GridView3_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView3.EditIndex = e.NewEditIndex;
        GridView3.DataSource = dn.DSHoiDap();
        GridView3.DataBind();
    }
    protected void GridView3_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView3.PageIndex = e.NewPageIndex;
        GridView3.DataSource = dn.DSHoiDap();
        GridView3.DataBind(); ;
    }
    protected void GridView3_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView3.EditIndex = -1;
        GridView3.DataSource = dn.DSHoiDap();
        GridView3.DataBind();
    }
  
    protected void Button7_Click(object sender, EventArgs e)
    {
        try
        {
            for (int i = 0; i < GridView3.Rows.Count; i++)
            {
                CheckBox chb = (CheckBox)GridView3.Rows[i].Cells[0].FindControl("CheckBox1");
                if (chb.Checked == true)
                {
                    string nguoihoi = GridView3.Rows[i].Cells[1].Text;
                    dn.XoaHoiDap(nguoihoi);
                }
            }
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;

        }
        GridView3.DataSource = dn.DSHoiDap();
        GridView3.DataBind();
    }
}
